package com.keyancompany.zhongbaopingtai.activity;

import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.keyancompany.zhongbaopingtai.ConstansUrl;
import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.api.UserAPI;
import com.keyancompany.zhongbaopingtai.model.EventBusEntity;
import com.keyancompany.zhongbaopingtai.model.FindModel;
import com.keyancompany.zhongbaopingtai.utils.IntentUtils;
import com.keyancompany.zhongbaopingtai.utils.T;
import com.keyancompany.zhongbaopingtai.weight.CircleImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.Bind;
import butterknife.BindString;
import butterknife.OnClick;

/**
 * 资金账户
 * <p>
 * Created by firefox on 2016/6/5.
 */
public class BanlanceActivity extends BaseActivity {


    @BindString(R.string.moeny_account_text)
    String title;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.banlance_text)
    TextView banlanceText;
    @Bind(R.id.banlance_watting_parent)
    LinearLayout banlanceWattingParent;
    @Bind(R.id.banlance_yue_parent)
    LinearLayout banlanceYueParent;
    @Bind(R.id.account_password_parent)
    LinearLayout accountPasswordParent;
    @Bind(R.id.tixian_account_parent)
    LinearLayout tixianAccountParent;
    @Bind(R.id.yue_tixian_parent)
    LinearLayout yueTixianParent;
    @Bind(R.id.account)
    TextView account;
    @Bind(R.id.avatar)
    CircleImageView avatar;
    @Bind(R.id.balance_history_parent)
    LinearLayout balanceHistoryParent;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_banlance;
    }

    @Override
    protected int getMenuId() {
        return 0;
    }

    @Override
    protected void initToolBar() {
        toolbar.setTitle(title);
        setSupportActionBar(toolbar);
        initHomeAsUpEnable(toolbar);
    }

    @Override
    protected void setUpViews() {
        EventBus.getDefault().register(this);
        ImageLoader.getInstance().displayImage(UserAPI.getCurrentUser().getHeadpic(), avatar);
        account.setText(UserAPI.getCurrentUser().getZhifubao());
    }

    /**
     * 事件订阅者自定义的接收方法
     *
     * @param event
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(EventBusEntity event) {
//        //（1）将事件发布者发布的数据作为文本修改内容
//        msgFragment.setText(event.data);
        //（2）将事件发布者发布的数据作为方法执行的区分
        switch (event.getType()) {
            case EventBusEntity.Type.ACCOUNT_NAME:

                account.setText(UserAPI.getCurrentUser().getZhifubao());
                break;
        }
    }

    @OnClick(R.id.account_password_parent) //支付密码
    public void ToPayPassword(View view) {
        IntentUtils.startActivity(this, PayPasswordActivity.class);
    }

    @OnClick(R.id.balance_history_parent) //资金流水
    public void toBalanceHistory(View view) {
        IntentUtils.startActivity(this, BalanceHistoryActivity.class);
    }

    @OnClick(R.id.tixian_account_parent) //未到账余额
    public void wattingParent(View view) {
//        if (TextUtils.isEmpty(UserAPI.getCurrentUser().getZhifubao())) {
//            T.show(this, "请设置支付密码", Toast.LENGTH_SHORT);
//        } else
        IntentUtils.startActivity(this, GetAccountActivity.class);
    }

    @OnClick(R.id.yue_tixian_parent) //余额提现
    public void banlanceTiXian(View view) {
        if (TextUtils.isEmpty(UserAPI.getCurrentUser().getZhifubao()))
            T.show(this, "请先设置提现账号", Toast.LENGTH_SHORT);
        IntentUtils.startActivity(this, BalanceTransferActivity.class);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
